<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>Ajax 01 Page</h1>
    <button onclick="doAjaxStart()">Ajax Get Start</button>
    <span id="result"></span>
</div>

<script>
    function doAjaxStart() {
        //1.creat xhr 对象
        let xhr = new XMLHttpRequest();
        //2.设置状态监听
        xhr.onreadystatechange=function () {
            if (xhr.readyState==4&&xhr.status==200){//4 表示服务端响应到客户端结果 200表示服务端处理请求的过程是OK的
                //debugger
                let str= xhr.responseText;
                console.log(str);
                let result =document.getElementById("result");
                result.innerHTML=str;
            }
        }
        //3.建立一个与服务端指定URL的链接
        xhr.open("post","/doAjaxStart",true);
        //4.发送请求
        xhr.send(null);
        console.log("===main====")
    }
</script>
</body>
</html>